<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Base Sprite</title>
</head>
<body>
  <canvas id="mycanvas" width="600" height="600"></canvas>
  <script src="/js/sprite-core.js"></script>
  <script>
    const {Layer, Label} = spritejs,
      context = document.getElementById('mycanvas').getContext('2d');

    const layer = new Layer({context});

    const label = new Label('click me');
    label.attr({
      anchor: 0.5,
      pos: [300, 300],
      size: [200, 70],
      lineHeight: 70,
      font: '48px Arial',
      textAlign: 'center',
      border: {
        width: 6,
        color: 'red',
        style: 'solid',
      },
    });

    layer.append(label);

    const transition = label.transition(0.3);
    label.on('mousedown', (evt) => {
      // console.log(label.attr('width'))
      transition.attr({
        width: width => width + 50,
      });
    });

    label.on('mouseup', (evt) => {
      transition.reverse();
    });

    mycanvas.addEventListener('mousedown', (evt) => {
      const {offsetX, offsetY} = evt;
      layer.dispatchEvent(
        ['mousedown'],
        {layerX: offsetX, layerY: offsetY, originEvent: evt}
      );
    });
    mycanvas.addEventListener('mouseup', (evt) => {
      const {offsetX, offsetY} = evt;
      layer.dispatchEvent(
        ['mouseup'],
        {layerX: offsetX, layerY: offsetY, originEvent: evt}
      );
    });
  </script>
</body>
</html>